package com.uchengwang.ui.cm_ui.uu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.uu.bean.ChooseItemBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by U城网 on 2018/1/22.
 */

public class ChooseItemIconAdapter extends BaseAdapter {
    private Context context;
    private List<ChooseItemBean> list;

    public ChooseItemIconAdapter(Context context, List<ChooseItemBean> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ChooseVH holder = null;
        if (view == null){
            holder = new ChooseVH();
            view = LayoutInflater.from(context).inflate(R.layout.layout_item_choose_icon, null, false);
            holder.choose_ln = (LinearLayout) view.findViewById(R.id.choose_ln);
            holder.chooseIcon_img = (ImageView) view.findViewById(R.id.chooseIcon_img);
            holder.choose_text = (TextView) view.findViewById(R.id.choose_text);

            view.setTag(holder);
            AutoUtils.autoSize(view);
        }else {
            holder = (ChooseVH) view.getTag();
        }

        ChooseItemBean bean = list.get(i);

//        if (i ==0){
//            //第一个
//            holder.choose_ln.setBackgroundResource(R.drawable.selector_linear_bg_top);
//        }else if (i ==resIds.length){
//            //最后一个
//            holder.choose_ln.setBackgroundResource(R.drawable.selector_linear_bg_bottom);
//        }

        if (bean.getBgId() >0){
            holder.choose_ln.setBackgroundResource(bean.getBgId());
        }
        holder.choose_text.setText(bean.getTitle());
        if (bean.getTextColor() >0){
            holder.choose_text.setTextColor(context.getResources().getColor(bean.getTextColor()));
        }
        ImageManager.getInstance().loadImage(context, holder.chooseIcon_img, bean.getResId(), ImageManager.ImageType.NARMOL);

        return view;
    }

    private class ChooseVH{
        private LinearLayout choose_ln;
        private ImageView chooseIcon_img;
        private TextView choose_text;
    }
}
